<template>
  <div class="baseInfo">
    <div class="map">
      <div class="mapContent">
        <mapH5 :landDetailData="landDetailData"></mapH5>
      </div>
      <div class="mapTest">
        地址：<span>{{ landInfo.address }}</span>
      </div>
    </div>
    <div class="device" v-if="deviceData.length !== 0">
      <div class="deviceData" v-for="(item,index) in deviceData" :key="index">
        <div class="tit">
          <div>{{item.name}}</div>
        </div>
        <div class="content">{{item.value}} {{item.com}}</div>
        <div class="time"> 更新时间：{{ item.time }} </div>
      </div>
    </div>
    <div class="none" v-else>
      <img src="./../assets/Group 177.png" alt="">
      <div class="noneTest">暂无设备信息</div>
    </div>
  </div>
</template>z

<script>
import { getLandInfoApi } from '@/api/tracing'
import {
  getNewSoilDeviceApi,
  getNewWeatherApi
} from '@/api/device.js'
import mapH5 from '../components/map.vue'
export default {
  name: 'ShuzhongtianH5BaseInfo',
  components: {
    mapH5
  },

  data () {
    return {
      params: {},
      landInfo: {},
      landDetailData: {},
      deviceData: []
    }
  },

  mounted () {
    this.params = this.$store.state.suyuan
    this.getLandInfo(this.params)
    this.getDeviceData(this.params)
  },

  methods: {
    async getLandInfo (params) {
      const res = await getLandInfoApi(params)
      console.log(res.data)
      this.landInfo = res.data[0]
      this.landDetailData = res.data[0]
    },
    async getDeviceData (params) {
      // 清空防止数据累加出现重复
      const soilData = []
      const weatherData = []

      // 土壤
      const res2 = await getNewSoilDeviceApi(params)
      if (res2.data !== null) {
        const soilTime = res2.data.time.substring(res2.data.time.length - 8)
        soilData.push({
          name: '土壤·温度',
          value: res2.data.temperature,
          com: '℃',
          id: 1,
          time: soilTime
        }, {
          name: '土壤·湿度',
          value: res2.data.humidity,
          com: '%',
          id: 2,
          time: soilTime

        }, {
          name: '土壤·电导率',
          value: res2.data.conductivity,
          com: 'μS/cm',
          id: 3,
          time: soilTime

        })
      }

      // 气象
      const res3 = await getNewWeatherApi(params)
      if (res3.data !== null) {
        const weatherTime = res3.data.time.substring(res3.data.time.length - 8)
        weatherData.push({
          name: '气象·温度',
          value: res3.data.temperature,
          com: '℃',
          id: 1,
          time: weatherTime
        }, {
          name: '气象·湿度',
          value: res3.data.humidity,
          com: '%',
          id: 2,
          time: weatherTime
        })
      }
      this.deviceData = [...weatherData, ...soilData]
    }
  }
}
</script>
<style lang="scss" scoped>
.baseInfo {
  padding: 24px 12px 0px;
  min-height: 600px;
  // overflow-y: auto;
  .map {
    width: 319px;
    height: 288px;
    background: #f3f4f3;
    border-radius: 8px 8px 8px 8px;
    margin-bottom: 10px;
    .mapContent {
      width: 319px;
      height: 240px;
      border-radius: 0px 0px 0px 0px;
    }
    .mapTest {
      height: 48px;
      width: 319px;
      line-height: 48px;
      padding-left: 8px;
      font-weight: 600;
      overflow: hidden;
      padding: 0 10px;
      span {
        color: #19b560;
        font-size: 12px;
      }
    }
  }
  .device {
    // width: 319px;
    // height: 182px;
    margin-bottom: 20px;
    border-radius: 8px 8px 8px 8px;
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
      // 设备数据格
  .deviceData {
    width: 154px;
    height: 109px;
    background: #FFFFFF;
    border-radius: 8px;
    padding: 12px 0 0;
    flex-shrink: 0;
    border: 1px solid #E8F8EF;
    margin-bottom: 8px;

    .tit {
      display: flex;
      justify-content: space-between;
      border-left: 3px solid #F57C00;
      padding: 0 12px;
      font-family: PingFang SC, PingFang SC;
      font-weight: 400;
      font-size: 12px;
      color: #0A241B;
      margin-bottom: 18px;
    }

    .content {
      font-family: PingFang SC, PingFang SC;
      font-weight: 500;
      font-size: 18px;
      color: #0A241B;
      padding-left: 10px;
      margin-bottom: 12px;
    }

    .time {
      width: 100%;
      height: 28px;
      line-height: 28px;
      font-weight: 400;
      font-size: 12px;
      color: #9BA5A2;
      padding-left: 12px;
      border-top: 1px solid #E8F8EF;
    }
  }

  .deviceData:nth-child(1) {
    .tit {
      border-left: 3px solid #F87273;
    }
  }

  .deviceData:nth-child(2) {
    .tit {
      border-left: 3px solid #68C0FF;
    }
  }

  .deviceData:nth-child(3) {
    .tit {
      border-left: 3px solid #FFBD24;
    }
  }

  .deviceData:nth-child(4) {
    .tit {
      border-left: 3px solid #6B91FF;
    }
  }
    .deviceData:nth-child(4) {
    .tit {
      border-left: 3px solid #8c4a95;
    }
  }
  }
}
.none {
  text-align: center;
  margin-top: 30px;

  img {
    width: 213px;
    height: 228px;
  }
  .noneTest {
    margin-top: -100px;
    color: #71807B ;
  }
}
</style>
